<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class login extends CI_Controller {
	public function __construct() 
	{       
            parent::__construct();
            $this->load->library('session');
            $this->load->helper('url');
            $this->load->library('form_validation');
            $this->load->library("pagination");
            $this->load->model('user_model');
	}
        
    public function index() {
        $session = $this->session->userdata('login');
        //echo sha1('admin');
        if($session!=null){
            redirect(site_url().'/home');
        }else{
            $this->load->view('theme/header2');
            $this->load->view('login/login');
            $this->load->view('theme/footer');
        }
    }
    public function masuk(){
        $username = $this->input->post('username');
        $password = $this->input->post('password');
        $coba_login = $this->user_model->coba_login($username,$password);
        var_dump($coba_login);
        if($coba_login['hasil']==true){
            $this->session->set_userdata(array('login'=>$coba_login['detil_pengguna']));
            redirect(site_url().'/home');
        }else{
            redirect(site_url().'/login?error=1');
        }
    }
    public function keluar(){
        $this->session->unset_userdata('login');
        redirect(site_url());
    }
}
?>